home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / sdf / hdf_rdwr.pro < prev    next >
Text File  |  1997-07-08  |  2KB  |  74 lines

  1. ;
  2. ;    Simple example #1
  3. ;
  4. ;    Save a matrix as a SDS
  5. ;
  6. PRO MakeHDFData, filename
  7.  
  8.     ;    Check for a filename. Provide a default if none
  9.     ;    is given.
  10.     IF N_ELEMENTS(filename) EQ 0 THEN filename="hdf_example.hdf"
  11.  
  12.     ;    Create (or overwrite) a Scientific Data Set (SDS)
  13.     ;    We always want to write the first SDS so...
  14.         xray=float(dist(100,200))
  15.     myRANGE=[max(xray,min=min_xray),min_xray]
  16.         ;
  17.     sd_id=HDF_SD_START(filename,/CREATE)
  18.     sds_id=HDF_SD_CREATE(sd_id,'brain X-ray',[100,200],/FLOAT)
  19.     HDF_SD_SETINFO,sds_id,FILL=0.0,LABEL='X-Ray of my brain', $
  20.                UNIT='Furlongs per Fortnight',$
  21.                RANGE=myRANGE
  22.     ;
  23.     ; Write labels to each of the dimensions
  24.     ;
  25.     HDF_SD_DIMSET,HDF_SD_DIMGETID(sds_id,0),NAME='Width',LABEL='Width of my brain'
  26.     HDF_SD_DIMSET,HDF_SD_DIMGETID(sds_id,1),NAME='Height',LABEL='Height of my brain'
  27.  
  28.     ;    Create and write the data
  29.     HDF_SD_ADDDATA, sds_id, xray
  30.  
  31.     ;    Done Close down the SDS
  32.  
  33.     HDF_SD_ENDACCESS,sds_id
  34.     HDF_SD_END,sd_id
  35. END
  36.  
  37. PRO ReadHDFData, filename
  38.  
  39.     ;    See if there is anything there to read
  40.  
  41.     sd_id=HDF_SD_START(filename)
  42.         HDF_SD_FILEINFO,sd_id,NumSDS,attributes
  43.  
  44.     IF NumSDS LT 1 THEN Message, "No Scientific Data Sets in File"
  45.  
  46.     ;    Find out about the first SDS
  47.  
  48.     sds_id=HDF_SD_SELECT(sd_id,0)
  49.     help,sds_id
  50.     HDF_SD_GETINFO,sds_id,RANGE=RANGE
  51.     HDF_SD_GETINFO,sds_id,NDIMS=NDIMS,LABEL=LABEL,DIMS=DIMS,TYPE=TYPE
  52.     HDF_SD_GETDATA,sds_id,xray_out
  53.     ;
  54.     ; Close down the HDF file
  55.         ;
  56.     HDF_SD_ENDACCESS,sds_id
  57.     HDF_SD_END,sd_id
  58.         ;
  59.     help,NDIMS,RANGE,LABEL,DIMS,TYPE
  60.     Print,'Displaying Data'
  61.     window,xsize=DIMS[0],ysize=DIMS[1]
  62.     erase
  63.     loadct,8
  64.     TVSCL, xray_out
  65.     XYOUTS, !d.x_size/2, !d.y_size - 20, ALIGNMENT=0.5, /DEVICE, $
  66.         STRING(LABEL),charsize=0.75
  67. END
  68.  
  69. PRO hdf_rdwr,Filename
  70.     Print, 'Writing Data' & MakeHDFData,filename
  71.     Print, 'Reading Data' & ReadHDFData,filename
  72. END
  73.  
  74.